package com.qk.mapper;

import com.qk.dto.UserDto;
import com.qk.entity.User;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface UserMapper {
    List<User> selectlist(UserDto userdto);

    @Update("update user set username=#{username},password=#{password},name=#{name},phone=#{phone},email=#{email},gender=#{gender},status=#{status},dept_id=#{deptId},role_id=#{roleId},image=#{image},remark=#{remark},create_time=#{createTime},update_time=#{updateTime} where id=#{id}")
    void update(User user);

    void deleteById(List<Integer> ids);

    //@Update("update user set username=#{username},password=#{password},name=#{name},phone=#{phone},email=#{email},gender=#{gender},status=#{status},dept_id=#{deptId},role_id=#{roleId},image=#{image},remark=#{remark},update_time=#{updateTime} where id=#{id}")
    @Select("select id,username,password,name,phone,email,gender,status,dept_id,role_id,image,remark,create_time,update_time from user where id= #{id}")
    User getById(Integer id);
    @Insert("insert into user(id,username,password,name,phone,email,gender,status,dept_id,role_id,image,remark,create_time,update_time) values (#{id},#{username},#{password},#{name},#{phone},#{email},#{gender},#{status},#{deptId},#{roleId},#{image},#{remark},#{createTime},#{updateTime})")
    void add(User user);

    @Select("select * from user")
    List<User> all();

    @Select("select * from user u,role r where u.role_id = r.id and status = 1 and r.label = #{roleLabel}")
    List<User> getByRole(String roleLabel);

    @Select("select id, username, password, name, phone, email, gender, status, dept_id, role_id, image, remark, create_time, update_time from user u where u.dept_id = #{deptId}")
    List<User> getByDept(Integer deptId);

    @Select("select u.*,r.label roleLabel from user u left join role r on u.role_id = r.id where username = #{username}")
    User selectByRole(String username);
}
